/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.ilongfei.web.formdemo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;




@Controller
@RequestMapping(value = "/demo/form/")
public class CheckboxesController {

	@RequestMapping(value="checkboxes", method = RequestMethod.GET)
	public String checkboxesshow(Model model) {
		 User user = new User();  
		   List<String> roles = new ArrayList<String>();  
		   roles.add("role1");  
		   roles.add("role3");  
		   user.setRoles(roles);  
		   List<String> roleList = new ArrayList<String>();  
		   roleList.add("role1");  
		   roleList.add("role2");  
		   roleList.add("role3");  
		   model.addAttribute("user", user);  
		   model.addAttribute("roleList", roleList);  
		return "/demo/form/checkboxes";
	}

	@RequestMapping(value = "checkboxes", method = RequestMethod.POST)
	public String createForm(Model model) {
		model.addAttribute("message", model.toString());
		System.out.println(model.toString());
		return "/demo/form/checkboxes";
	}

}
